package com.zxy.ziems.server.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.dto.PointDto;
import com.zxy.ziems.server.dto.PointQueryDto;
import com.zxy.ziems.server.service.PointService;
import com.zxy.ziems.server.vo.PointVo;
import com.zxy.ziems.server.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName PointController
 * @Description
 * @Author 邓伟
 * @Date 2023/11/23 16:27
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/point")
public class PointController {

    @Autowired
    private PointService pointService;

    @PostMapping("addOrUpdate")
    public JsonResponse addOrUpdate (@RequestBody @Validated PointDto pointDto) {
        pointService.addOrUpdate(pointDto);
        return JsonResponse.SUCCESS();
    }

    @PostMapping("startOrStop")
    public JsonResponse startOrStop (@RequestBody PointDto pointDto) {
        pointService.startOrStop(pointDto);
        return JsonResponse.SUCCESS();
    }

    @PostMapping("/page/list")
    public JsonResponse<PageResult<PointVo>> pageList(@RequestBody PointQueryDto pointQueryDto) {
        PageResult<PointVo> pageResult = pointService.pageList(pointQueryDto);
        return JsonResponse.SUCCESS(pageResult);
    }

    @GetMapping("/delete")
    public JsonResponse delete (@RequestParam(value = "pointId") String pointId) {
        pointService.delete(pointId);
        return JsonResponse.SUCCESS();
    }

}
